var widthDiv = 200;
var heightDiv = 20;
var d = null ;
var inputOp = null;
var hopId = null;
var htmlId = null;
var d_1 = null;

initDtree = function (array){
	d = new dTree('d');
	for(var i=0;i<array.length;i++)
	{
		var a = array[i];
		if(a[1]==-1)
		{
			d.add(a[0],a[1],a[2]);
		}else{
			d.add(a[0],a[1],a[2],"javascript:addData('"+a[0]+","+a[2]+"')");	
		}
	}
	var dtreeDiv = document.getElementById("dtreeDiv");
	dtreeDiv.style.display="none";
	dtreeDiv.innerHTML = d; 
}

initDtree_1 = function (array){
	d_1 = new dTree('d_1');
	for(var i=0;i<array.length;i++)
	{
		var a = array[i];
		if(a[1]==-1)
		{
			d_1.add(a[0],a[1],a[2]);
		}else{
			d_1.add(a[0],a[1],a[2],"javascript:addData_1('"+a[0]+","+a[2]+"')");	
		}
	}
	
	var dtreeDiv = document.getElementById("dtreeDiv");
	dtreeDiv.style.display="none";
	dtreeDiv.innerHTML = d_1; 
}

initDtree_2 = function (array){
	d_2 = new dTree('d_2');
	for(var i=0;i<array.length;i++)
	{
		var a = array[i];
		if(a[1]==-1)
		{
			d_2.add(a[0],a[1],a[2]);
		}else{
			d_2.add(a[0],a[1],a[2],"javascript:addData_2('"+a[0]+","+a[2]+"')");	
		}
	}
	
	var dtreeDiv = document.getElementById("dtreeDiv_1");
	dtreeDiv.style.display="none";
	dtreeDiv.innerHTML = d_2; 
}
//----------------------------------------------------------------------------------

//计算当前坐标
DtreegetPos = function (el,ePro)				/// Get Absolute Position
{
	var ePos=0;
	while(el!=null)
	{
		ePos+=el["offset"+ePro];
		el=el.offsetParent;
	}
	return ePos;
}
//----------------------------------------------------------------------------------

//显示
showDtree = function (op,hid){
	hopId = hid;
	inputOp = op.id;
	normalExit = true;
	var dtreeDiv = document.getElementById("dtreeDiv");
	dtreeDiv.style.backgroundColor="#CED2F0";
	dtreeDiv.style.filter="Alpha(Opacity=80)";
	dtreeDiv.style.pixelLeft=DtreegetPos(op,"Left");
	dtreeDiv.style.pixelTop=DtreegetPos(op,"Top") + op.offsetHeight;
	dtreeDiv.style.display=(dtreeDiv.style.display=="none")?"block":"none";
}

showDtree_1 = function (op,hid){
	hopId = hid
	inputOp = op.id;
	normalExit = true;
	var dtreeDiv = document.getElementById("dtreeDiv");
	dtreeDiv.style.backgroundColor="#CED2F0";
	dtreeDiv.style.filter="Alpha(Opacity=80)";
	dtreeDiv.style.pixelLeft=DtreegetPos(op,"Left");
	dtreeDiv.style.pixelTop=DtreegetPos(op,"Top") + op.offsetHeight;
	dtreeDiv.style.display=(dtreeDiv.style.display=="none")?"block":"none";
}

showDtree_2 = function (op,hid){
	hopId = hid
	inputOp = op.id;
	normalExit = true;
	var dtreeDiv = document.getElementById("dtreeDiv_1");
	dtreeDiv.style.backgroundColor="#CED2F0";
	dtreeDiv.style.filter="Alpha(Opacity=80)";
	dtreeDiv.style.pixelLeft=DtreegetPos(op,"Left");
	dtreeDiv.style.pixelTop=DtreegetPos(op,"Top") + op.offsetHeight;
	dtreeDiv.style.display=(dtreeDiv.style.display=="none")?"block":"none";
}
//----------------------------------------------------------------------------------

//为文本框添加数据
addData = function(data){
	if(inputOp!=null)
	{
		var text = document.getElementById(inputOp).value;
		var inputText = data.substr(data.indexOf(",")+1,data.length);
		if(text!=null&&text!=""){
			inputText = text+"、"+inputText;
		}
		document.getElementById(inputOp).innerText+=inputText;
		
		if(hopId!=null){
			var hop = document.getElementById(hopId).value;
			var hinputText = data.substr(data.indexOf(",")+1,data.length);
			if(hop!=null&&hop!=""){
				hinputText = hop+"、"+hinputText;
			}
			document.getElementById(hopId).innerText+=hinputText;
		}
		
		
		document.getElementById("dtreeDiv").style.display="none";
		
		normalExit = false;
		
	}
}

addData_1 = function(data){
	if(inputOp!=null)
	{
		var text = document.getElementById(inputOp).value;
		var inputText = data.substr(data.indexOf(",")+1,data.length);
		document.getElementById(inputOp).innerText=inputText;
		if(hopId!=null){
			var hop = document.getElementById(hopId).value;
			var hinputText = data.substr(0,data.indexOf(","));
			document.getElementById(hopId).innerText=hinputText;
		}
		document.getElementById("dtreeDiv").style.display="none";
		normalExit = false;
	}
}

addData_2 = function(data){
	if(inputOp!=null)
	{
		var text = document.getElementById(inputOp).value;
		var inputText = data.substr(data.indexOf(",")+1,data.length);
		document.getElementById(inputOp).innerText=inputText;
		if(hopId!=null){
			var hop = document.getElementById(hopId).value;
			var hinputText = data.substr(0,data.indexOf(","));
			document.getElementById(hopId).innerText=hinputText;
		}
		document.getElementById("dtreeDiv_1").style.display="none";
		normalExit = false;
	}
}

//----------------------------------------------------------------------------------
document.onclick = function()
{
	with(window.event)
	{
		var srce = srcElement.id;
		/******************利用正则表达式将图形【+ ，-】中的ID替换掉************************/
		var re = new RegExp("jd([0-9]){1,}","ig");
		var sd = new RegExp("sd([0-9]){1,}","ig"); 
		if(srce.match(sd))
		{
			while(srce.match(sd))
			{
				srce = srce.replace(sd,"sd");
			}
		}
		if(srce.match(re))
		{
			while(srce.match(re))
			{
				srce = srce.replace(re,"jd");
			}
		}
		//***********************************************" +
//		if(srcElement.getAttribute("Author")==null && (srce != "dtreeDiv"  )&& srce!=inputOp && srce!="jd"&&srce!="sd")
//		{
//			document.getElementById("dtreeDiv").style.display="none";
//			normalExit = false;
//		}
//		if(srcElement.getAttribute("Author")==null && (srce != "dtreeDiv_1"  )&& srce!=inputOp && srce!="jd"&&srce!="sd")
//		{
//			document.getElementById("dtreeDiv_1").style.display="none";
//			normalExit = false;
//		}
	}
	//----------------------------------------------------------------------------------
}

